import Vue from "vue";
import router from "@/router";
import store from "@/store";
import { findRouterMeta } from "@/util/public";

Vue.directive("permission", {
  inserted(el: any, binding) {
    const { action, effect } = binding.value;
    const nowRouter = findRouterMeta(router.currentRoute.path, store.state.routers);
    const { operation } =nowRouter.meta;
    if (!operation.includes(action)) {
      if (effect === "disabled") {
        el.disabled = true;
        el.classList.add("is-disabled");
      } else el.parentNode.removeChild(el);
    }
  },
});
